import Vue from 'vue'
import Router from 'vue-router'
import routeList from './modules'
import { getURLQueryString } from '@/utils/common'
import nprogress from "nprogress";
import "nprogress/nprogress.css";
Vue.use(Router)
//解决重复点击相同路由报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

// 不显示圈圈
nprogress.configure({
	showSpinner: false
});

const router = new Router({
	//	mode:'history',
	//	base: '',
	routes: [{
			path: '/',
			name: 'Index',
			redirect: '/home',
			component: () =>
				import("@/pages/Index"),
			children: [{
					path: '/home',
					name: 'Home',
					meta: {
						title: "首页"
					},
					component: () =>
						import("@/pages/Home"),
				},
				...routeList
			]
		},
		{
			path: '*',
			name: '404',
			redirect: '/',
		}
	]
})
router.beforeEach((to, from, next) => {
	window.scrollTo(0,0)
	nprogress.start();
	next();
});

router.afterEach((to, from) => {
	if(to.meta && to.meta.title) {
		document.title = to.meta.title;
	}
	nprogress.done();
});

export default router